package com.cinc.ebc.pp.workOrderProcess.controller;

import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cinc.ebc.pp.workOrderProcess.model.PpWorkOrderProcessReportModel;
import com.cinc.ebc.pp.workOrderProcess.vo.PpWorkOrderProcessPage;
import com.cinc.ebc.pp.workOrderProcess.vo.PpWorkOrderProcessReportPage;
import com.cinc.ebc.sd.model.SdSalesOrderDetailOutModel;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import com.cinc.ebc.pp.workOrderProcess.entity.PpWorkOrderProcess;
import com.cinc.ebc.pp.workOrderProcess.service.IPpWorkOrderProcessService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 生产工单加工明细
 * @Author: jeecg-boot
 * @Date:   2024-04-05
 * @Version: V1.0
 */
@Api(tags="生产工单加工明细")
@RestController
@RequestMapping("/pp/workOrderProcess")
@Slf4j
public class PpWorkOrderProcessController extends JeecgController<PpWorkOrderProcess, IPpWorkOrderProcessService> {
	@Autowired
	private IPpWorkOrderProcessService ppWorkOrderProcessService;

	/**
	 * 分页列表查询
	 *
	 * @param ppWorkOrderProcess
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "生产工单加工明细-分页列表查询")
	@ApiOperation(value="生产工单加工明细-分页列表查询", notes="生产工单加工明细-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(PpWorkOrderProcess ppWorkOrderProcess,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<PpWorkOrderProcess> queryWrapper = QueryGenerator.initQueryWrapper(ppWorkOrderProcess, req.getParameterMap());
		Page<PpWorkOrderProcess> page = new Page<PpWorkOrderProcess>(pageNo, pageSize);
		IPage<PpWorkOrderProcess> pageList = ppWorkOrderProcessService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	 /**
	  * 待汇报列表查询
	  *
	  * @param processPage
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 @AutoLog(value = "生产工单加工明细-分页列表查询")
	 @ApiOperation(value="生产工单加工明细-分页列表查询", notes="生产工单加工明细-分页列表查询")
	 @GetMapping(value = "/reportList")
	 public Result<?> queryPageReportList(PpWorkOrderProcessPage processPage,
										  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
										  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
										  HttpServletRequest req) {
		 Page<PpWorkOrderProcessReportModel> page = new Page<>(pageNo, pageSize);
		 IPage<PpWorkOrderProcessReportModel> pageList = ppWorkOrderProcessService.reportPage(page, processPage);
		 return Result.OK(pageList);
	 }

	/**
	 *   添加
	 *
	 * @param ppWorkOrderProcess
	 * @return
	 */
	@AutoLog(value = "生产工单加工明细-添加")
	@ApiOperation(value="生产工单加工明细-添加", notes="生产工单加工明细-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody PpWorkOrderProcess ppWorkOrderProcess) {
		ppWorkOrderProcessService.save(ppWorkOrderProcess);
		return Result.OK("添加成功！");
	}

	/**
	 *  编辑
	 *
	 * @param ppWorkOrderProcess
	 * @return
	 */
	@AutoLog(value = "生产工单加工明细-编辑")
	@ApiOperation(value="生产工单加工明细-编辑", notes="生产工单加工明细-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody PpWorkOrderProcess ppWorkOrderProcess) {
		ppWorkOrderProcessService.updateById(ppWorkOrderProcess);
		return Result.OK("编辑成功!");
	}

	@AutoLog(value = "生产工单加工明细-完工汇报")
	@ApiOperation(value="生产工单加工明细-完工汇报", notes="生产工单加工明细-完工汇报")
	@PutMapping(value = "/handleReport")
	public Result<?> handleReport(@RequestBody PpWorkOrderProcessReportPage reportPage) {
		ppWorkOrderProcessService.handleReport(reportPage);
		return Result.OK("汇报成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "生产工单加工明细-通过id删除")
	@ApiOperation(value="生产工单加工明细-通过id删除", notes="生产工单加工明细-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		ppWorkOrderProcessService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "生产工单加工明细-批量删除")
	@ApiOperation(value="生产工单加工明细-批量删除", notes="生产工单加工明细-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.ppWorkOrderProcessService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "生产工单加工明细-通过id查询")
	@ApiOperation(value="生产工单加工明细-通过id查询", notes="生产工单加工明细-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		PpWorkOrderProcess ppWorkOrderProcess = ppWorkOrderProcessService.getById(id);
		if(ppWorkOrderProcess==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(ppWorkOrderProcess);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param ppWorkOrderProcess
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, PpWorkOrderProcess ppWorkOrderProcess) {
        return super.exportXls(request, ppWorkOrderProcess, PpWorkOrderProcess.class, "生产工单加工明细");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, PpWorkOrderProcess.class);
    }

}
